﻿/*  ----------------------------------------------------------------------------
 *  Microsoft Public License (http://www.microsoft.com/opensource/licenses.mspx#Ms-PL)
 *  
 *  ----------------------------------------------------------------------------
 *  DynamicAspect
 *  ----------------------------------------------------------------------------
 *  File:       AuthenticationAspect.cs
 *  Author:     NiceWk (n9walker@hotmail.com)
 *  ----------------------------------------------------------------------------
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bizall.Dynamic.Aspect;

namespace BankSample
{
    class AuthenticationAspect : AspectBase
    {

        public AuthenticationAspect()
        {
    //        Enabled = false;
        }

        public override void OnBeforeMethodCall(WeavingContext context)
        {
            if (context.InvokeMemberBinder.Name != "ShowAccount")
            {
                Console.WriteLine("Please enter user ID: ");
                var userid = Console.ReadLine();

                Console.WriteLine("Please enter password: ");
                var password = Console.ReadLine();

                if (CheckAccount(userid, password) == false)
                    throw new Exception("Invalid user account!");
            }
        }

        private bool CheckAccount(string userid, string password)
        {
            return userid.ToLower() == "user" && password == "p@ssw0rd";
        }
  
    }
}